package com.yxj.dries.lib.network.api;

import androidx.annotation.MainThread;
import androidx.annotation.WorkerThread;
import androidx.lifecycle.LiveData;

import com.yxj.dries.lib.network.R;

public abstract class NetworkBoundResource<ResultType, RequestType> {

    // 调用以将API响应的结果保存到数据库中
    @WorkerThread
    protected abstract void saveCallResult(RequestType item);
    // 与数据库中的数据一起调用，以决定是否从网络中获取可能更新的数据。
    @WorkerThread
    protected abstract Boolean shouldFetch(ResultType data);
    // 调用以从数据库中获取缓存的数据
    @MainThread
    protected abstract LiveData<ResultType> loadFromDb();
    // Called to create the API call.
    @MainThread
    protected abstract LiveData<ApiResponse<RequestType>> createCall();
    //在获取失败时调用。子类可能需要重置组件
    //类似速率限制器。
    protected abstract void onFetchFailed();
    // Returns a LiveData object that represents the resource that's implemented
    // in the base class.
    abstract LiveData<ResultType> asLiveData();
}
